package vip.liux.backend.adapter.web;

import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.liux.application.dots.PagedResultDto;
import vip.liux.application.dots.PagedResultRequestDto;
import vip.liux.backend.application.service.pay.PayDemoWithdrawService;
import vip.liux.backend.application.service.pay.dto.demo.PayDemoWithdrawCreateDto;
import vip.liux.backend.application.service.pay.dto.notify.PayNotifyResp;
import vip.liux.backend.application.service.pay.dto.notify.PayTransferNotifyDto;
import vip.liux.contracts.models.pay.PayDemoWithdraw;

import javax.validation.Valid;


@RestController
@RequestMapping("/api/pay/demo/withdraw")
@Validated
public class PayDemoWithdrawController {

    @Resource
    private PayDemoWithdrawService demoWithdrawService;

    @PostMapping
    public PayDemoWithdraw createDemoWithdraw(@Valid @RequestBody PayDemoWithdrawCreateDto createReqVO) {
        return demoWithdrawService.createDemoWithdraw(createReqVO);
    }

    @PostMapping("/transfer")
    public String transferDemoWithdraw(@RequestParam("id") Long id) {
        return demoWithdrawService.transferDemoWithdraw(id);
    }

    @GetMapping("/page")
    public PagedResultDto<PayDemoWithdraw> getDemoWithdrawPage(PagedResultRequestDto input) {
        return demoWithdrawService.getDemoWithdrawPage(input);
    }

    @PostMapping("/notify")
    public PayNotifyResp updateDemoWithdrawTransferred(@RequestBody PayTransferNotifyDto notifyDto) {
        demoWithdrawService.updateDemoWithdrawTransferred(Long.valueOf(notifyDto.getMerchantTransferId()),
                notifyDto.getPayTransferNo());
        return new PayNotifyResp("success", 0);
    }
}
